
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 10/07/2011 17:48:11
-- Generated from EDMX file: C:\codeplex\Private\MedAgendaPrivatePractice\ModelLayer\MedAgendaDBModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [MedAgendaDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_CancelReason_80530D95A2CECE61253485E77E6505E3]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Order_] DROP CONSTRAINT [FK_CancelReason_80530D95A2CECE61253485E77E6505E3];
GO
IF OBJECT_ID(N'[dbo].[FK_Category_391FE00AC169D57F49E7B4487FECB594]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderAttachment_] DROP CONSTRAINT [FK_Category_391FE00AC169D57F49E7B4487FECB594];
GO
IF OBJECT_ID(N'[dbo].[FK_Category_B68C520BD91F5CF70666DD5302B7D28E]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PatientAttachment_] DROP CONSTRAINT [FK_Category_B68C520BD91F5CF70666DD5302B7D28E];
GO
IF OBJECT_ID(N'[dbo].[FK_Equipment_5F1032B3A0DBA8E7DB2E9C4ADB30C993]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PatientProfileTelephoneNumber_] DROP CONSTRAINT [FK_Equipment_5F1032B3A0DBA8E7DB2E9C4ADB30C993];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderOID_09C180895D5C20FFD8CD4BC829D20F50]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderAttachment_] DROP CONSTRAINT [FK_OrderOID_09C180895D5C20FFD8CD4BC829D20F50];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderOID_EB5391E4018893D738181E74A7B4C92B]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Procedure_] DROP CONSTRAINT [FK_OrderOID_EB5391E4018893D738181E74A7B4C92B];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderStatusEnum_Order_]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Order_] DROP CONSTRAINT [FK_OrderStatusEnum_Order_];
GO
IF OBJECT_ID(N'[dbo].[FK_PatientOID_054667830389F2241E4D6D0EB08E7B46]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Order_] DROP CONSTRAINT [FK_PatientOID_054667830389F2241E4D6D0EB08E7B46];
GO
IF OBJECT_ID(N'[dbo].[FK_PatientOID_1730B951630835E3F5FF1D644E86EFCA]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PatientProfile_] DROP CONSTRAINT [FK_PatientOID_1730B951630835E3F5FF1D644E86EFCA];
GO
IF OBJECT_ID(N'[dbo].[FK_PatientOID_7E92A48DD9F2187BCC97CC178751D054]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PatientAttachment_] DROP CONSTRAINT [FK_PatientOID_7E92A48DD9F2187BCC97CC178751D054];
GO
IF OBJECT_ID(N'[dbo].[FK_PatientOID_E6C7038BE70155060687C374BE641018]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Visit_] DROP CONSTRAINT [FK_PatientOID_E6C7038BE70155060687C374BE641018];
GO
IF OBJECT_ID(N'[dbo].[FK_PatientProfileOID_30E0CDC53C23CFEFAAC08A1B280ED4A4]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PatientProfileContactPerson_] DROP CONSTRAINT [FK_PatientProfileOID_30E0CDC53C23CFEFAAC08A1B280ED4A4];
GO
IF OBJECT_ID(N'[dbo].[FK_PatientProfileOID_48E8A8F216EEC3B1EF8E9BBD6B0615FA]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PatientProfileAddress_] DROP CONSTRAINT [FK_PatientProfileOID_48E8A8F216EEC3B1EF8E9BBD6B0615FA];
GO
IF OBJECT_ID(N'[dbo].[FK_PatientProfileOID_995CCD42F22C902F73A4054805FB5B41]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PatientProfileEmailAddress_] DROP CONSTRAINT [FK_PatientProfileOID_995CCD42F22C902F73A4054805FB5B41];
GO
IF OBJECT_ID(N'[dbo].[FK_PatientProfileOID_DA2A8F24E9EEED134B5EFC2E6F5602CB]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PatientProfileTelephoneNumber_] DROP CONSTRAINT [FK_PatientProfileOID_DA2A8F24E9EEED134B5EFC2E6F5602CB];
GO
IF OBJECT_ID(N'[dbo].[FK_PatientTypeEnum_PatientProfile_]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PatientProfile_] DROP CONSTRAINT [FK_PatientTypeEnum_PatientProfile_];
GO
IF OBJECT_ID(N'[dbo].[FK_PrimaryLanguage_8E0D0B9385D0A9A4C06EBB5BDA8CAE78]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PatientProfile_] DROP CONSTRAINT [FK_PrimaryLanguage_8E0D0B9385D0A9A4C06EBB5BDA8CAE78];
GO
IF OBJECT_ID(N'[dbo].[FK_Priority_1DCC83BE7EE341A2FC585EB6390CE7E9]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Order_] DROP CONSTRAINT [FK_Priority_1DCC83BE7EE341A2FC585EB6390CE7E9];
GO
IF OBJECT_ID(N'[dbo].[FK_Relationship_B281425E3E45AFE2FCBC25ADDF1CC753]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PatientProfileContactPerson_] DROP CONSTRAINT [FK_Relationship_B281425E3E45AFE2FCBC25ADDF1CC753];
GO
IF OBJECT_ID(N'[dbo].[FK_Religion_5C8D488B0C03E00D08B6779DA226B13D]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PatientProfile_] DROP CONSTRAINT [FK_Religion_5C8D488B0C03E00D08B6779DA226B13D];
GO
IF OBJECT_ID(N'[dbo].[FK_ReplacementOrderOID_F8A1352C51B0F5C1178B246CB9D1BE9B]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Order_] DROP CONSTRAINT [FK_ReplacementOrderOID_F8A1352C51B0F5C1178B246CB9D1BE9B];
GO
IF OBJECT_ID(N'[dbo].[FK_Sex_CDEEC16E473A40DCECC8A8F0B107DC19]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PatientProfile_] DROP CONSTRAINT [FK_Sex_CDEEC16E473A40DCECC8A8F0B107DC19];
GO
IF OBJECT_ID(N'[dbo].[FK_Status_EC31B9C320DB0F8E2AAFCE6BE943E79D]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Visit_] DROP CONSTRAINT [FK_Status_EC31B9C320DB0F8E2AAFCE6BE943E79D];
GO
IF OBJECT_ID(N'[dbo].[FK_Type_5B35F21CAAA580FAF201927F3CE41BD0]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PatientProfileAddress_] DROP CONSTRAINT [FK_Type_5B35F21CAAA580FAF201927F3CE41BD0];
GO
IF OBJECT_ID(N'[dbo].[FK_Type_D1570BC72928E5BA4F1074853C108DBF]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PatientProfileContactPerson_] DROP CONSTRAINT [FK_Type_D1570BC72928E5BA4F1074853C108DBF];
GO
IF OBJECT_ID(N'[dbo].[FK_Use_A3FC5E3B5A2F703378A9418B9FD33C96]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PatientProfileTelephoneNumber_] DROP CONSTRAINT [FK_Use_A3FC5E3B5A2F703378A9418B9FD33C96];
GO
IF OBJECT_ID(N'[dbo].[FK_UserOID_37C3E18DECA55F5059911C9A2BAE7E88]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserSession_] DROP CONSTRAINT [FK_UserOID_37C3E18DECA55F5059911C9A2BAE7E88];
GO
IF OBJECT_ID(N'[dbo].[FK_VisitOID_8E58FFCF8C8FFC65AE0FBB5F741CD1F5]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Order_] DROP CONSTRAINT [FK_VisitOID_8E58FFCF8C8FFC65AE0FBB5F741CD1F5];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[AddressTypeEnum_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AddressTypeEnum_];
GO
IF OBJECT_ID(N'[dbo].[ContactPersonRelationshipEnum_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ContactPersonRelationshipEnum_];
GO
IF OBJECT_ID(N'[dbo].[ContactPersonTypeEnum_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ContactPersonTypeEnum_];
GO
IF OBJECT_ID(N'[dbo].[InformationAuthorityEnum_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[InformationAuthorityEnum_];
GO
IF OBJECT_ID(N'[dbo].[Message_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Message_];
GO
IF OBJECT_ID(N'[dbo].[Order_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Order_];
GO
IF OBJECT_ID(N'[dbo].[OrderAttachment_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrderAttachment_];
GO
IF OBJECT_ID(N'[dbo].[OrderAttachmentCategoryEnum_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrderAttachmentCategoryEnum_];
GO
IF OBJECT_ID(N'[dbo].[OrderCancelReasonEnum_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrderCancelReasonEnum_];
GO
IF OBJECT_ID(N'[dbo].[OrderPriorityEnum_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrderPriorityEnum_];
GO
IF OBJECT_ID(N'[dbo].[OrderStatusEnum_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrderStatusEnum_];
GO
IF OBJECT_ID(N'[dbo].[Patient_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Patient_];
GO
IF OBJECT_ID(N'[dbo].[PatientAttachment_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PatientAttachment_];
GO
IF OBJECT_ID(N'[dbo].[PatientAttachmentCategoryEnum_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PatientAttachmentCategoryEnum_];
GO
IF OBJECT_ID(N'[dbo].[PatientProfile_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PatientProfile_];
GO
IF OBJECT_ID(N'[dbo].[PatientProfileAddress_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PatientProfileAddress_];
GO
IF OBJECT_ID(N'[dbo].[PatientProfileContactPerson_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PatientProfileContactPerson_];
GO
IF OBJECT_ID(N'[dbo].[PatientProfileEmailAddress_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PatientProfileEmailAddress_];
GO
IF OBJECT_ID(N'[dbo].[PatientProfileTelephoneNumber_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PatientProfileTelephoneNumber_];
GO
IF OBJECT_ID(N'[dbo].[PatientTypeEnum_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PatientTypeEnum_];
GO
IF OBJECT_ID(N'[dbo].[Procedure_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Procedure_];
GO
IF OBJECT_ID(N'[dbo].[ReligionEnum_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ReligionEnum_];
GO
IF OBJECT_ID(N'[dbo].[SexEnum_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SexEnum_];
GO
IF OBJECT_ID(N'[dbo].[SpokenLanguageEnum_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SpokenLanguageEnum_];
GO
IF OBJECT_ID(N'[dbo].[TelephoneEquipmentEnum_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TelephoneEquipmentEnum_];
GO
IF OBJECT_ID(N'[dbo].[TelephoneUseEnum_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TelephoneUseEnum_];
GO
IF OBJECT_ID(N'[dbo].[User_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[User_];
GO
IF OBJECT_ID(N'[dbo].[UserSession_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserSession_];
GO
IF OBJECT_ID(N'[dbo].[Visit_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Visit_];
GO
IF OBJECT_ID(N'[dbo].[VisitStatusEnum_]', 'U') IS NOT NULL
    DROP TABLE [dbo].[VisitStatusEnum_];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'AddressTypeEnum_'
CREATE TABLE [dbo].[AddressTypeEnum_] (
    [Code_] nvarchar(255)  NOT NULL,
    [Value_] nvarchar(50)  NULL,
    [Description_] nvarchar(200)  NULL,
    [DisplayOrder_] real  NULL,
    [Deactivated_] bit  NOT NULL
);
GO

-- Creating table 'ContactPersonRelationshipEnum_'
CREATE TABLE [dbo].[ContactPersonRelationshipEnum_] (
    [Code_] nvarchar(255)  NOT NULL,
    [Value_] nvarchar(50)  NULL,
    [Description_] nvarchar(200)  NULL,
    [DisplayOrder_] real  NULL,
    [Deactivated_] bit  NOT NULL
);
GO

-- Creating table 'ContactPersonTypeEnum_'
CREATE TABLE [dbo].[ContactPersonTypeEnum_] (
    [Code_] nvarchar(255)  NOT NULL,
    [Value_] nvarchar(50)  NULL,
    [Description_] nvarchar(200)  NULL,
    [DisplayOrder_] real  NULL,
    [Deactivated_] bit  NOT NULL
);
GO

-- Creating table 'Order_'
CREATE TABLE [dbo].[Order_] (
    [OID_] uniqueidentifier  NOT NULL,
    [Version_] int  NOT NULL,
    [PlacerNumber_] nvarchar(30)  NULL,
    [AccessionNumber_] nvarchar(30)  NOT NULL,
    [EnteredTime_] datetime  NOT NULL,
    [EnteredComment_] nvarchar(255)  NULL,
    [SchedulingRequestTime_] datetime  NULL,
    [ScheduledStartTime_] datetime  NULL,
    [StartTime_] datetime  NULL,
    [EndTime_] datetime  NULL,
    [ReasonForStudy_] nvarchar(400)  NULL,
    [CancelComment_] nvarchar(255)  NULL,
    [OrderCancelReasonEnum__Code_] nvarchar(255)  NULL,
    [Patient__OID_] uniqueidentifier  NOT NULL,
    [OrderPriorityEnum__Code_] nvarchar(255)  NOT NULL,
    [Order_2_OID_] uniqueidentifier  NULL,
    [Visit__OID_] uniqueidentifier  NOT NULL,
    [OrderStatusEnum_Code_] nvarchar(255)  NOT NULL
);
GO

-- Creating table 'OrderAttachment_'
CREATE TABLE [dbo].[OrderAttachment_] (
    [AttachedTime_] datetime  NOT NULL,
    [OID_] uniqueidentifier  NOT NULL,
    [Order__OID_] uniqueidentifier  NOT NULL,
    [OrderAttachmentCategoryEnum__Code_] nvarchar(255)  NULL
);
GO

-- Creating table 'OrderAttachmentCategoryEnum_'
CREATE TABLE [dbo].[OrderAttachmentCategoryEnum_] (
    [Code_] nvarchar(255)  NOT NULL,
    [Value_] nvarchar(50)  NULL,
    [Description_] nvarchar(200)  NULL,
    [DisplayOrder_] real  NULL,
    [Deactivated_] bit  NOT NULL
);
GO

-- Creating table 'OrderCancelReasonEnum_'
CREATE TABLE [dbo].[OrderCancelReasonEnum_] (
    [Code_] nvarchar(255)  NOT NULL,
    [Value_] nvarchar(50)  NULL,
    [Description_] nvarchar(200)  NULL,
    [DisplayOrder_] real  NULL,
    [Deactivated_] bit  NOT NULL
);
GO

-- Creating table 'OrderPriorityEnum_'
CREATE TABLE [dbo].[OrderPriorityEnum_] (
    [Code_] nvarchar(255)  NOT NULL,
    [Value_] nvarchar(50)  NULL,
    [Description_] nvarchar(200)  NULL,
    [DisplayOrder_] real  NULL,
    [Deactivated_] bit  NOT NULL
);
GO

-- Creating table 'OrderStatusEnum_'
CREATE TABLE [dbo].[OrderStatusEnum_] (
    [Code_] nvarchar(255)  NOT NULL,
    [Value_] nvarchar(50)  NULL,
    [Description_] nvarchar(200)  NULL,
    [DisplayOrder_] real  NULL,
    [Deactivated_] bit  NOT NULL
);
GO

-- Creating table 'Patient_'
CREATE TABLE [dbo].[Patient_] (
    [OID_] uniqueidentifier  NOT NULL,
    [Version_] int  NOT NULL
);
GO

-- Creating table 'PatientAttachment_'
CREATE TABLE [dbo].[PatientAttachment_] (
    [AttachedTime_] datetime  NOT NULL,
    [OID_] uniqueidentifier  NOT NULL,
    [Patient__OID_] uniqueidentifier  NOT NULL,
    [PatientAttachmentCategoryEnum__Code_] nvarchar(255)  NULL
);
GO

-- Creating table 'PatientAttachmentCategoryEnum_'
CREATE TABLE [dbo].[PatientAttachmentCategoryEnum_] (
    [Code_] nvarchar(255)  NOT NULL,
    [Value_] nvarchar(50)  NULL,
    [Description_] nvarchar(200)  NULL,
    [DisplayOrder_] real  NULL,
    [Deactivated_] bit  NOT NULL
);
GO

-- Creating table 'PatientProfile_'
CREATE TABLE [dbo].[PatientProfile_] (
    [OID_] uniqueidentifier  NOT NULL,
    [Version_] int  NOT NULL,
    [MrnId_] nvarchar(50)  NOT NULL,
    [HealthcardId_] nvarchar(30)  NULL,
    [HealthcardVersionCode_] nvarchar(20)  NULL,
    [HealthcardExpiryDate_] datetime  NULL,
    [FamilyName_] nvarchar(40)  NOT NULL,
    [GivenName_] nvarchar(40)  NOT NULL,
    [MiddleName_] nvarchar(40)  NULL,
    [Prefix_] nvarchar(10)  NULL,
    [Suffix_] nvarchar(10)  NULL,
    [Degree_] nvarchar(10)  NULL,
    [DateOfBirth_] datetime  NULL,
    [DeathIndicator_] bit  NOT NULL,
    [TimeOfDeath_] datetime  NULL,
    [IdDocumentNumber_] nvarchar(50)  NULL,
    [Patient__OID_] uniqueidentifier  NOT NULL,
    [SpokenLanguageEnum__Code_] nvarchar(255)  NULL,
    [ReligionEnum__Code_] nvarchar(255)  NULL,
    [SexEnum__Code_] nvarchar(255)  NOT NULL,
    [VipPatient_] bit  NULL,
    [PatientTypeEnum_Code_] nvarchar(255)  NULL,
    [MrnAssigningAuthority_Code_] nvarchar(255)  NULL,
    [InformationAuthorityEnum_Code_] nvarchar(255)  NOT NULL
);
GO

-- Creating table 'PatientProfileAddress_'
CREATE TABLE [dbo].[PatientProfileAddress_] (
    [Street_] nvarchar(100)  NOT NULL,
    [Unit_] nvarchar(50)  NULL,
    [City_] nvarchar(50)  NOT NULL,
    [Province_] nvarchar(50)  NOT NULL,
    [PostalCode_] nvarchar(20)  NULL,
    [Country_] nvarchar(50)  NULL,
    [ValidFrom_] datetime  NULL,
    [ValidUntil_] datetime  NULL,
    [OID_] uniqueidentifier  NOT NULL,
    [AddressTypeEnum__Code_] nvarchar(255)  NOT NULL,
    [PatientProfile__OID_] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'PatientProfileContactPerson_'
CREATE TABLE [dbo].[PatientProfileContactPerson_] (
    [Name_] nvarchar(50)  NOT NULL,
    [Address_] nvarchar(255)  NULL,
    [HomePhone_] nvarchar(25)  NULL,
    [BusinessPhone_] nvarchar(25)  NULL,
    [OID_] uniqueidentifier  NOT NULL,
    [ContactPersonRelationshipEnum__Code_] nvarchar(255)  NOT NULL,
    [ContactPersonTypeEnum__Code_] nvarchar(255)  NOT NULL,
    [PatientProfile__OID_] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'PatientProfileEmailAddress_'
CREATE TABLE [dbo].[PatientProfileEmailAddress_] (
    [Address_] nvarchar(255)  NOT NULL,
    [ValidFrom_] datetime  NULL,
    [ValidUntil_] datetime  NULL,
    [OID_] uniqueidentifier  NOT NULL,
    [PatientProfile__OID_] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'PatientProfileTelephoneNumber_'
CREATE TABLE [dbo].[PatientProfileTelephoneNumber_] (
    [CountryCode_] nvarchar(10)  NULL,
    [AreaCode_] nvarchar(10)  NULL,
    [Number_] nvarchar(50)  NOT NULL,
    [Extension_] nvarchar(10)  NULL,
    [ValidFrom_] datetime  NULL,
    [ValidUntil_] datetime  NULL,
    [OID_] uniqueidentifier  NOT NULL,
    [PatientProfile__OID_] uniqueidentifier  NOT NULL,
    [TelephoneEquipmentEnum__Code_] nvarchar(255)  NOT NULL,
    [TelephoneUseEnum__Code_] nvarchar(255)  NOT NULL
);
GO

-- Creating table 'PatientTypeEnum_'
CREATE TABLE [dbo].[PatientTypeEnum_] (
    [Code_] nvarchar(255)  NOT NULL,
    [Value_] nvarchar(50)  NULL,
    [Description_] nvarchar(200)  NULL,
    [DisplayOrder_] real  NULL,
    [Deactivated_] bit  NOT NULL
);
GO

-- Creating table 'Procedure_'
CREATE TABLE [dbo].[Procedure_] (
    [OID_] uniqueidentifier  NOT NULL,
    [VisitDate_] datetime  NULL,
    [Order__OID_] uniqueidentifier  NOT NULL,
    [Description_] nvarchar(max)  NULL
);
GO

-- Creating table 'ReligionEnum_'
CREATE TABLE [dbo].[ReligionEnum_] (
    [Code_] nvarchar(255)  NOT NULL,
    [Value_] nvarchar(50)  NULL,
    [Description_] nvarchar(200)  NULL,
    [DisplayOrder_] real  NULL,
    [Deactivated_] bit  NOT NULL
);
GO

-- Creating table 'SexEnum_'
CREATE TABLE [dbo].[SexEnum_] (
    [Code_] nvarchar(255)  NOT NULL,
    [Value_] nvarchar(50)  NULL,
    [Description_] nvarchar(200)  NULL,
    [DisplayOrder_] real  NULL,
    [Deactivated_] bit  NOT NULL
);
GO

-- Creating table 'SpokenLanguageEnum_'
CREATE TABLE [dbo].[SpokenLanguageEnum_] (
    [Code_] nvarchar(255)  NOT NULL,
    [Value_] nvarchar(50)  NULL,
    [Description_] nvarchar(200)  NULL,
    [DisplayOrder_] real  NULL,
    [Deactivated_] bit  NOT NULL
);
GO

-- Creating table 'TelephoneEquipmentEnum_'
CREATE TABLE [dbo].[TelephoneEquipmentEnum_] (
    [Code_] nvarchar(255)  NOT NULL,
    [Value_] nvarchar(50)  NULL,
    [Description_] nvarchar(200)  NULL,
    [DisplayOrder_] real  NULL,
    [Deactivated_] bit  NOT NULL
);
GO

-- Creating table 'TelephoneUseEnum_'
CREATE TABLE [dbo].[TelephoneUseEnum_] (
    [Code_] nvarchar(255)  NOT NULL,
    [Value_] nvarchar(50)  NULL,
    [Description_] nvarchar(200)  NULL,
    [DisplayOrder_] real  NULL,
    [Deactivated_] bit  NOT NULL
);
GO

-- Creating table 'User_'
CREATE TABLE [dbo].[User_] (
    [OID_] uniqueidentifier  NOT NULL,
    [Version_] int  NOT NULL,
    [UserName_] nvarchar(255)  NOT NULL,
    [PasswordSalt_] nvarchar(255)  NOT NULL,
    [PasswordSaltedHash_] nvarchar(255)  NOT NULL,
    [PasswordExpiryDate_] datetime  NULL,
    [DisplayName_] nvarchar(255)  NULL,
    [ValidFrom_] datetime  NULL,
    [ValidUntil_] datetime  NULL,
    [Enabled_] bit  NOT NULL,
    [CreationTime_] datetime  NOT NULL,
    [LastLoginTime_] datetime  NULL
);
GO

-- Creating table 'UserSession_'
CREATE TABLE [dbo].[UserSession_] (
    [OID_] uniqueidentifier  NOT NULL,
    [HostName_] nvarchar(255)  NULL,
    [Application_] nvarchar(255)  NULL,
    [SessionId_] nvarchar(255)  NOT NULL,
    [CreationTime_] datetime  NOT NULL,
    [ExpiryTime_] datetime  NOT NULL,
    [User__OID_] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'Visit_'
CREATE TABLE [dbo].[Visit_] (
    [OID_] uniqueidentifier  NOT NULL,
    [Version_] int  NOT NULL,
    [VisitNumberId_] nvarchar(50)  NOT NULL,
    [AdmitTime_] datetime  NULL,
    [DischargeTime_] datetime  NULL,
    [DischargeDisposition_] nvarchar(100)  NULL,
    [PreadmitNumber_] nvarchar(20)  NULL,
    [Patient__OID_] uniqueidentifier  NOT NULL,
    [PatientClassEnum__Code_] nvarchar(255)  NULL,
    [PatientTypeEnum__Code_] nvarchar(255)  NULL,
    [VisitStatusEnum__Code_] nvarchar(255)  NOT NULL,
    [IsAppointment_] bit  NOT NULL
);
GO

-- Creating table 'VisitStatusEnum_'
CREATE TABLE [dbo].[VisitStatusEnum_] (
    [Code_] nvarchar(255)  NOT NULL,
    [Value_] nvarchar(50)  NULL,
    [Description_] nvarchar(200)  NULL,
    [DisplayOrder_] real  NULL,
    [Deactivated_] bit  NOT NULL
);
GO

-- Creating table 'Message_'
CREATE TABLE [dbo].[Message_] (
    [OID_] uniqueidentifier  NOT NULL,
    [Message_1] nvarchar(200)  NOT NULL,
    [Option_] nvarchar(200)  NOT NULL
);
GO

-- Creating table 'InformationAuthorityEnum_'
CREATE TABLE [dbo].[InformationAuthorityEnum_] (
    [Code_] nvarchar(255)  NOT NULL,
    [Value_] nvarchar(50)  NULL,
    [Description_] nvarchar(200)  NULL,
    [DisplayOrder_] real  NULL,
    [Deactivated_] bit  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Code_] in table 'AddressTypeEnum_'
ALTER TABLE [dbo].[AddressTypeEnum_]
ADD CONSTRAINT [PK_AddressTypeEnum_]
    PRIMARY KEY CLUSTERED ([Code_] ASC);
GO

-- Creating primary key on [Code_] in table 'ContactPersonRelationshipEnum_'
ALTER TABLE [dbo].[ContactPersonRelationshipEnum_]
ADD CONSTRAINT [PK_ContactPersonRelationshipEnum_]
    PRIMARY KEY CLUSTERED ([Code_] ASC);
GO

-- Creating primary key on [Code_] in table 'ContactPersonTypeEnum_'
ALTER TABLE [dbo].[ContactPersonTypeEnum_]
ADD CONSTRAINT [PK_ContactPersonTypeEnum_]
    PRIMARY KEY CLUSTERED ([Code_] ASC);
GO

-- Creating primary key on [OID_] in table 'Order_'
ALTER TABLE [dbo].[Order_]
ADD CONSTRAINT [PK_Order_]
    PRIMARY KEY CLUSTERED ([OID_] ASC);
GO

-- Creating primary key on [OID_] in table 'OrderAttachment_'
ALTER TABLE [dbo].[OrderAttachment_]
ADD CONSTRAINT [PK_OrderAttachment_]
    PRIMARY KEY CLUSTERED ([OID_] ASC);
GO

-- Creating primary key on [Code_] in table 'OrderAttachmentCategoryEnum_'
ALTER TABLE [dbo].[OrderAttachmentCategoryEnum_]
ADD CONSTRAINT [PK_OrderAttachmentCategoryEnum_]
    PRIMARY KEY CLUSTERED ([Code_] ASC);
GO

-- Creating primary key on [Code_] in table 'OrderCancelReasonEnum_'
ALTER TABLE [dbo].[OrderCancelReasonEnum_]
ADD CONSTRAINT [PK_OrderCancelReasonEnum_]
    PRIMARY KEY CLUSTERED ([Code_] ASC);
GO

-- Creating primary key on [Code_] in table 'OrderPriorityEnum_'
ALTER TABLE [dbo].[OrderPriorityEnum_]
ADD CONSTRAINT [PK_OrderPriorityEnum_]
    PRIMARY KEY CLUSTERED ([Code_] ASC);
GO

-- Creating primary key on [Code_] in table 'OrderStatusEnum_'
ALTER TABLE [dbo].[OrderStatusEnum_]
ADD CONSTRAINT [PK_OrderStatusEnum_]
    PRIMARY KEY CLUSTERED ([Code_] ASC);
GO

-- Creating primary key on [OID_] in table 'Patient_'
ALTER TABLE [dbo].[Patient_]
ADD CONSTRAINT [PK_Patient_]
    PRIMARY KEY CLUSTERED ([OID_] ASC);
GO

-- Creating primary key on [OID_] in table 'PatientAttachment_'
ALTER TABLE [dbo].[PatientAttachment_]
ADD CONSTRAINT [PK_PatientAttachment_]
    PRIMARY KEY CLUSTERED ([OID_] ASC);
GO

-- Creating primary key on [Code_] in table 'PatientAttachmentCategoryEnum_'
ALTER TABLE [dbo].[PatientAttachmentCategoryEnum_]
ADD CONSTRAINT [PK_PatientAttachmentCategoryEnum_]
    PRIMARY KEY CLUSTERED ([Code_] ASC);
GO

-- Creating primary key on [OID_] in table 'PatientProfile_'
ALTER TABLE [dbo].[PatientProfile_]
ADD CONSTRAINT [PK_PatientProfile_]
    PRIMARY KEY CLUSTERED ([OID_] ASC);
GO

-- Creating primary key on [OID_] in table 'PatientProfileAddress_'
ALTER TABLE [dbo].[PatientProfileAddress_]
ADD CONSTRAINT [PK_PatientProfileAddress_]
    PRIMARY KEY CLUSTERED ([OID_] ASC);
GO

-- Creating primary key on [OID_] in table 'PatientProfileContactPerson_'
ALTER TABLE [dbo].[PatientProfileContactPerson_]
ADD CONSTRAINT [PK_PatientProfileContactPerson_]
    PRIMARY KEY CLUSTERED ([OID_] ASC);
GO

-- Creating primary key on [OID_] in table 'PatientProfileEmailAddress_'
ALTER TABLE [dbo].[PatientProfileEmailAddress_]
ADD CONSTRAINT [PK_PatientProfileEmailAddress_]
    PRIMARY KEY CLUSTERED ([OID_] ASC);
GO

-- Creating primary key on [OID_] in table 'PatientProfileTelephoneNumber_'
ALTER TABLE [dbo].[PatientProfileTelephoneNumber_]
ADD CONSTRAINT [PK_PatientProfileTelephoneNumber_]
    PRIMARY KEY CLUSTERED ([OID_] ASC);
GO

-- Creating primary key on [Code_] in table 'PatientTypeEnum_'
ALTER TABLE [dbo].[PatientTypeEnum_]
ADD CONSTRAINT [PK_PatientTypeEnum_]
    PRIMARY KEY CLUSTERED ([Code_] ASC);
GO

-- Creating primary key on [OID_] in table 'Procedure_'
ALTER TABLE [dbo].[Procedure_]
ADD CONSTRAINT [PK_Procedure_]
    PRIMARY KEY CLUSTERED ([OID_] ASC);
GO

-- Creating primary key on [Code_] in table 'ReligionEnum_'
ALTER TABLE [dbo].[ReligionEnum_]
ADD CONSTRAINT [PK_ReligionEnum_]
    PRIMARY KEY CLUSTERED ([Code_] ASC);
GO

-- Creating primary key on [Code_] in table 'SexEnum_'
ALTER TABLE [dbo].[SexEnum_]
ADD CONSTRAINT [PK_SexEnum_]
    PRIMARY KEY CLUSTERED ([Code_] ASC);
GO

-- Creating primary key on [Code_] in table 'SpokenLanguageEnum_'
ALTER TABLE [dbo].[SpokenLanguageEnum_]
ADD CONSTRAINT [PK_SpokenLanguageEnum_]
    PRIMARY KEY CLUSTERED ([Code_] ASC);
GO

-- Creating primary key on [Code_] in table 'TelephoneEquipmentEnum_'
ALTER TABLE [dbo].[TelephoneEquipmentEnum_]
ADD CONSTRAINT [PK_TelephoneEquipmentEnum_]
    PRIMARY KEY CLUSTERED ([Code_] ASC);
GO

-- Creating primary key on [Code_] in table 'TelephoneUseEnum_'
ALTER TABLE [dbo].[TelephoneUseEnum_]
ADD CONSTRAINT [PK_TelephoneUseEnum_]
    PRIMARY KEY CLUSTERED ([Code_] ASC);
GO

-- Creating primary key on [OID_] in table 'User_'
ALTER TABLE [dbo].[User_]
ADD CONSTRAINT [PK_User_]
    PRIMARY KEY CLUSTERED ([OID_] ASC);
GO

-- Creating primary key on [OID_] in table 'UserSession_'
ALTER TABLE [dbo].[UserSession_]
ADD CONSTRAINT [PK_UserSession_]
    PRIMARY KEY CLUSTERED ([OID_] ASC);
GO

-- Creating primary key on [OID_] in table 'Visit_'
ALTER TABLE [dbo].[Visit_]
ADD CONSTRAINT [PK_Visit_]
    PRIMARY KEY CLUSTERED ([OID_] ASC);
GO

-- Creating primary key on [Code_] in table 'VisitStatusEnum_'
ALTER TABLE [dbo].[VisitStatusEnum_]
ADD CONSTRAINT [PK_VisitStatusEnum_]
    PRIMARY KEY CLUSTERED ([Code_] ASC);
GO

-- Creating primary key on [OID_] in table 'Message_'
ALTER TABLE [dbo].[Message_]
ADD CONSTRAINT [PK_Message_]
    PRIMARY KEY CLUSTERED ([OID_] ASC);
GO

-- Creating primary key on [Code_] in table 'InformationAuthorityEnum_'
ALTER TABLE [dbo].[InformationAuthorityEnum_]
ADD CONSTRAINT [PK_InformationAuthorityEnum_]
    PRIMARY KEY CLUSTERED ([Code_] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [AddressTypeEnum__Code_] in table 'PatientProfileAddress_'
ALTER TABLE [dbo].[PatientProfileAddress_]
ADD CONSTRAINT [FK_Type_5B35F21CAAA580FAF201927F3CE41BD0]
    FOREIGN KEY ([AddressTypeEnum__Code_])
    REFERENCES [dbo].[AddressTypeEnum_]
        ([Code_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Type_5B35F21CAAA580FAF201927F3CE41BD0'
CREATE INDEX [IX_FK_Type_5B35F21CAAA580FAF201927F3CE41BD0]
ON [dbo].[PatientProfileAddress_]
    ([AddressTypeEnum__Code_]);
GO

-- Creating foreign key on [ContactPersonRelationshipEnum__Code_] in table 'PatientProfileContactPerson_'
ALTER TABLE [dbo].[PatientProfileContactPerson_]
ADD CONSTRAINT [FK_Relationship_B281425E3E45AFE2FCBC25ADDF1CC753]
    FOREIGN KEY ([ContactPersonRelationshipEnum__Code_])
    REFERENCES [dbo].[ContactPersonRelationshipEnum_]
        ([Code_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Relationship_B281425E3E45AFE2FCBC25ADDF1CC753'
CREATE INDEX [IX_FK_Relationship_B281425E3E45AFE2FCBC25ADDF1CC753]
ON [dbo].[PatientProfileContactPerson_]
    ([ContactPersonRelationshipEnum__Code_]);
GO

-- Creating foreign key on [ContactPersonTypeEnum__Code_] in table 'PatientProfileContactPerson_'
ALTER TABLE [dbo].[PatientProfileContactPerson_]
ADD CONSTRAINT [FK_Type_D1570BC72928E5BA4F1074853C108DBF]
    FOREIGN KEY ([ContactPersonTypeEnum__Code_])
    REFERENCES [dbo].[ContactPersonTypeEnum_]
        ([Code_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Type_D1570BC72928E5BA4F1074853C108DBF'
CREATE INDEX [IX_FK_Type_D1570BC72928E5BA4F1074853C108DBF]
ON [dbo].[PatientProfileContactPerson_]
    ([ContactPersonTypeEnum__Code_]);
GO

-- Creating foreign key on [OrderCancelReasonEnum__Code_] in table 'Order_'
ALTER TABLE [dbo].[Order_]
ADD CONSTRAINT [FK_CancelReason_80530D95A2CECE61253485E77E6505E3]
    FOREIGN KEY ([OrderCancelReasonEnum__Code_])
    REFERENCES [dbo].[OrderCancelReasonEnum_]
        ([Code_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CancelReason_80530D95A2CECE61253485E77E6505E3'
CREATE INDEX [IX_FK_CancelReason_80530D95A2CECE61253485E77E6505E3]
ON [dbo].[Order_]
    ([OrderCancelReasonEnum__Code_]);
GO

-- Creating foreign key on [Order__OID_] in table 'OrderAttachment_'
ALTER TABLE [dbo].[OrderAttachment_]
ADD CONSTRAINT [FK_OrderOID_09C180895D5C20FFD8CD4BC829D20F50]
    FOREIGN KEY ([Order__OID_])
    REFERENCES [dbo].[Order_]
        ([OID_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderOID_09C180895D5C20FFD8CD4BC829D20F50'
CREATE INDEX [IX_FK_OrderOID_09C180895D5C20FFD8CD4BC829D20F50]
ON [dbo].[OrderAttachment_]
    ([Order__OID_]);
GO

-- Creating foreign key on [Order__OID_] in table 'Procedure_'
ALTER TABLE [dbo].[Procedure_]
ADD CONSTRAINT [FK_OrderOID_EB5391E4018893D738181E74A7B4C92B]
    FOREIGN KEY ([Order__OID_])
    REFERENCES [dbo].[Order_]
        ([OID_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderOID_EB5391E4018893D738181E74A7B4C92B'
CREATE INDEX [IX_FK_OrderOID_EB5391E4018893D738181E74A7B4C92B]
ON [dbo].[Procedure_]
    ([Order__OID_]);
GO

-- Creating foreign key on [OrderStatusEnum_Code_] in table 'Order_'
ALTER TABLE [dbo].[Order_]
ADD CONSTRAINT [FK_OrderStatusEnum_Order_]
    FOREIGN KEY ([OrderStatusEnum_Code_])
    REFERENCES [dbo].[OrderStatusEnum_]
        ([Code_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderStatusEnum_Order_'
CREATE INDEX [IX_FK_OrderStatusEnum_Order_]
ON [dbo].[Order_]
    ([OrderStatusEnum_Code_]);
GO

-- Creating foreign key on [Patient__OID_] in table 'Order_'
ALTER TABLE [dbo].[Order_]
ADD CONSTRAINT [FK_PatientOID_054667830389F2241E4D6D0EB08E7B46]
    FOREIGN KEY ([Patient__OID_])
    REFERENCES [dbo].[Patient_]
        ([OID_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PatientOID_054667830389F2241E4D6D0EB08E7B46'
CREATE INDEX [IX_FK_PatientOID_054667830389F2241E4D6D0EB08E7B46]
ON [dbo].[Order_]
    ([Patient__OID_]);
GO

-- Creating foreign key on [OrderPriorityEnum__Code_] in table 'Order_'
ALTER TABLE [dbo].[Order_]
ADD CONSTRAINT [FK_Priority_1DCC83BE7EE341A2FC585EB6390CE7E9]
    FOREIGN KEY ([OrderPriorityEnum__Code_])
    REFERENCES [dbo].[OrderPriorityEnum_]
        ([Code_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Priority_1DCC83BE7EE341A2FC585EB6390CE7E9'
CREATE INDEX [IX_FK_Priority_1DCC83BE7EE341A2FC585EB6390CE7E9]
ON [dbo].[Order_]
    ([OrderPriorityEnum__Code_]);
GO

-- Creating foreign key on [Order_2_OID_] in table 'Order_'
ALTER TABLE [dbo].[Order_]
ADD CONSTRAINT [FK_ReplacementOrderOID_F8A1352C51B0F5C1178B246CB9D1BE9B]
    FOREIGN KEY ([Order_2_OID_])
    REFERENCES [dbo].[Order_]
        ([OID_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ReplacementOrderOID_F8A1352C51B0F5C1178B246CB9D1BE9B'
CREATE INDEX [IX_FK_ReplacementOrderOID_F8A1352C51B0F5C1178B246CB9D1BE9B]
ON [dbo].[Order_]
    ([Order_2_OID_]);
GO

-- Creating foreign key on [Visit__OID_] in table 'Order_'
ALTER TABLE [dbo].[Order_]
ADD CONSTRAINT [FK_VisitOID_8E58FFCF8C8FFC65AE0FBB5F741CD1F5]
    FOREIGN KEY ([Visit__OID_])
    REFERENCES [dbo].[Visit_]
        ([OID_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_VisitOID_8E58FFCF8C8FFC65AE0FBB5F741CD1F5'
CREATE INDEX [IX_FK_VisitOID_8E58FFCF8C8FFC65AE0FBB5F741CD1F5]
ON [dbo].[Order_]
    ([Visit__OID_]);
GO

-- Creating foreign key on [OrderAttachmentCategoryEnum__Code_] in table 'OrderAttachment_'
ALTER TABLE [dbo].[OrderAttachment_]
ADD CONSTRAINT [FK_Category_391FE00AC169D57F49E7B4487FECB594]
    FOREIGN KEY ([OrderAttachmentCategoryEnum__Code_])
    REFERENCES [dbo].[OrderAttachmentCategoryEnum_]
        ([Code_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Category_391FE00AC169D57F49E7B4487FECB594'
CREATE INDEX [IX_FK_Category_391FE00AC169D57F49E7B4487FECB594]
ON [dbo].[OrderAttachment_]
    ([OrderAttachmentCategoryEnum__Code_]);
GO

-- Creating foreign key on [Patient__OID_] in table 'PatientProfile_'
ALTER TABLE [dbo].[PatientProfile_]
ADD CONSTRAINT [FK_PatientOID_1730B951630835E3F5FF1D644E86EFCA]
    FOREIGN KEY ([Patient__OID_])
    REFERENCES [dbo].[Patient_]
        ([OID_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PatientOID_1730B951630835E3F5FF1D644E86EFCA'
CREATE INDEX [IX_FK_PatientOID_1730B951630835E3F5FF1D644E86EFCA]
ON [dbo].[PatientProfile_]
    ([Patient__OID_]);
GO

-- Creating foreign key on [Patient__OID_] in table 'PatientAttachment_'
ALTER TABLE [dbo].[PatientAttachment_]
ADD CONSTRAINT [FK_PatientOID_7E92A48DD9F2187BCC97CC178751D054]
    FOREIGN KEY ([Patient__OID_])
    REFERENCES [dbo].[Patient_]
        ([OID_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PatientOID_7E92A48DD9F2187BCC97CC178751D054'
CREATE INDEX [IX_FK_PatientOID_7E92A48DD9F2187BCC97CC178751D054]
ON [dbo].[PatientAttachment_]
    ([Patient__OID_]);
GO

-- Creating foreign key on [Patient__OID_] in table 'Visit_'
ALTER TABLE [dbo].[Visit_]
ADD CONSTRAINT [FK_PatientOID_E6C7038BE70155060687C374BE641018]
    FOREIGN KEY ([Patient__OID_])
    REFERENCES [dbo].[Patient_]
        ([OID_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PatientOID_E6C7038BE70155060687C374BE641018'
CREATE INDEX [IX_FK_PatientOID_E6C7038BE70155060687C374BE641018]
ON [dbo].[Visit_]
    ([Patient__OID_]);
GO

-- Creating foreign key on [PatientAttachmentCategoryEnum__Code_] in table 'PatientAttachment_'
ALTER TABLE [dbo].[PatientAttachment_]
ADD CONSTRAINT [FK_Category_B68C520BD91F5CF70666DD5302B7D28E]
    FOREIGN KEY ([PatientAttachmentCategoryEnum__Code_])
    REFERENCES [dbo].[PatientAttachmentCategoryEnum_]
        ([Code_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Category_B68C520BD91F5CF70666DD5302B7D28E'
CREATE INDEX [IX_FK_Category_B68C520BD91F5CF70666DD5302B7D28E]
ON [dbo].[PatientAttachment_]
    ([PatientAttachmentCategoryEnum__Code_]);
GO

-- Creating foreign key on [PatientProfile__OID_] in table 'PatientProfileContactPerson_'
ALTER TABLE [dbo].[PatientProfileContactPerson_]
ADD CONSTRAINT [FK_PatientProfileOID_30E0CDC53C23CFEFAAC08A1B280ED4A4]
    FOREIGN KEY ([PatientProfile__OID_])
    REFERENCES [dbo].[PatientProfile_]
        ([OID_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PatientProfileOID_30E0CDC53C23CFEFAAC08A1B280ED4A4'
CREATE INDEX [IX_FK_PatientProfileOID_30E0CDC53C23CFEFAAC08A1B280ED4A4]
ON [dbo].[PatientProfileContactPerson_]
    ([PatientProfile__OID_]);
GO

-- Creating foreign key on [PatientProfile__OID_] in table 'PatientProfileAddress_'
ALTER TABLE [dbo].[PatientProfileAddress_]
ADD CONSTRAINT [FK_PatientProfileOID_48E8A8F216EEC3B1EF8E9BBD6B0615FA]
    FOREIGN KEY ([PatientProfile__OID_])
    REFERENCES [dbo].[PatientProfile_]
        ([OID_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PatientProfileOID_48E8A8F216EEC3B1EF8E9BBD6B0615FA'
CREATE INDEX [IX_FK_PatientProfileOID_48E8A8F216EEC3B1EF8E9BBD6B0615FA]
ON [dbo].[PatientProfileAddress_]
    ([PatientProfile__OID_]);
GO

-- Creating foreign key on [PatientProfile__OID_] in table 'PatientProfileEmailAddress_'
ALTER TABLE [dbo].[PatientProfileEmailAddress_]
ADD CONSTRAINT [FK_PatientProfileOID_995CCD42F22C902F73A4054805FB5B41]
    FOREIGN KEY ([PatientProfile__OID_])
    REFERENCES [dbo].[PatientProfile_]
        ([OID_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PatientProfileOID_995CCD42F22C902F73A4054805FB5B41'
CREATE INDEX [IX_FK_PatientProfileOID_995CCD42F22C902F73A4054805FB5B41]
ON [dbo].[PatientProfileEmailAddress_]
    ([PatientProfile__OID_]);
GO

-- Creating foreign key on [PatientProfile__OID_] in table 'PatientProfileTelephoneNumber_'
ALTER TABLE [dbo].[PatientProfileTelephoneNumber_]
ADD CONSTRAINT [FK_PatientProfileOID_DA2A8F24E9EEED134B5EFC2E6F5602CB]
    FOREIGN KEY ([PatientProfile__OID_])
    REFERENCES [dbo].[PatientProfile_]
        ([OID_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PatientProfileOID_DA2A8F24E9EEED134B5EFC2E6F5602CB'
CREATE INDEX [IX_FK_PatientProfileOID_DA2A8F24E9EEED134B5EFC2E6F5602CB]
ON [dbo].[PatientProfileTelephoneNumber_]
    ([PatientProfile__OID_]);
GO

-- Creating foreign key on [PatientTypeEnum_Code_] in table 'PatientProfile_'
ALTER TABLE [dbo].[PatientProfile_]
ADD CONSTRAINT [FK_PatientTypeEnum_PatientProfile_]
    FOREIGN KEY ([PatientTypeEnum_Code_])
    REFERENCES [dbo].[PatientTypeEnum_]
        ([Code_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PatientTypeEnum_PatientProfile_'
CREATE INDEX [IX_FK_PatientTypeEnum_PatientProfile_]
ON [dbo].[PatientProfile_]
    ([PatientTypeEnum_Code_]);
GO

-- Creating foreign key on [SpokenLanguageEnum__Code_] in table 'PatientProfile_'
ALTER TABLE [dbo].[PatientProfile_]
ADD CONSTRAINT [FK_PrimaryLanguage_8E0D0B9385D0A9A4C06EBB5BDA8CAE78]
    FOREIGN KEY ([SpokenLanguageEnum__Code_])
    REFERENCES [dbo].[SpokenLanguageEnum_]
        ([Code_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PrimaryLanguage_8E0D0B9385D0A9A4C06EBB5BDA8CAE78'
CREATE INDEX [IX_FK_PrimaryLanguage_8E0D0B9385D0A9A4C06EBB5BDA8CAE78]
ON [dbo].[PatientProfile_]
    ([SpokenLanguageEnum__Code_]);
GO

-- Creating foreign key on [ReligionEnum__Code_] in table 'PatientProfile_'
ALTER TABLE [dbo].[PatientProfile_]
ADD CONSTRAINT [FK_Religion_5C8D488B0C03E00D08B6779DA226B13D]
    FOREIGN KEY ([ReligionEnum__Code_])
    REFERENCES [dbo].[ReligionEnum_]
        ([Code_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Religion_5C8D488B0C03E00D08B6779DA226B13D'
CREATE INDEX [IX_FK_Religion_5C8D488B0C03E00D08B6779DA226B13D]
ON [dbo].[PatientProfile_]
    ([ReligionEnum__Code_]);
GO

-- Creating foreign key on [SexEnum__Code_] in table 'PatientProfile_'
ALTER TABLE [dbo].[PatientProfile_]
ADD CONSTRAINT [FK_Sex_CDEEC16E473A40DCECC8A8F0B107DC19]
    FOREIGN KEY ([SexEnum__Code_])
    REFERENCES [dbo].[SexEnum_]
        ([Code_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Sex_CDEEC16E473A40DCECC8A8F0B107DC19'
CREATE INDEX [IX_FK_Sex_CDEEC16E473A40DCECC8A8F0B107DC19]
ON [dbo].[PatientProfile_]
    ([SexEnum__Code_]);
GO

-- Creating foreign key on [TelephoneEquipmentEnum__Code_] in table 'PatientProfileTelephoneNumber_'
ALTER TABLE [dbo].[PatientProfileTelephoneNumber_]
ADD CONSTRAINT [FK_Equipment_5F1032B3A0DBA8E7DB2E9C4ADB30C993]
    FOREIGN KEY ([TelephoneEquipmentEnum__Code_])
    REFERENCES [dbo].[TelephoneEquipmentEnum_]
        ([Code_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Equipment_5F1032B3A0DBA8E7DB2E9C4ADB30C993'
CREATE INDEX [IX_FK_Equipment_5F1032B3A0DBA8E7DB2E9C4ADB30C993]
ON [dbo].[PatientProfileTelephoneNumber_]
    ([TelephoneEquipmentEnum__Code_]);
GO

-- Creating foreign key on [TelephoneUseEnum__Code_] in table 'PatientProfileTelephoneNumber_'
ALTER TABLE [dbo].[PatientProfileTelephoneNumber_]
ADD CONSTRAINT [FK_Use_A3FC5E3B5A2F703378A9418B9FD33C96]
    FOREIGN KEY ([TelephoneUseEnum__Code_])
    REFERENCES [dbo].[TelephoneUseEnum_]
        ([Code_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Use_A3FC5E3B5A2F703378A9418B9FD33C96'
CREATE INDEX [IX_FK_Use_A3FC5E3B5A2F703378A9418B9FD33C96]
ON [dbo].[PatientProfileTelephoneNumber_]
    ([TelephoneUseEnum__Code_]);
GO

-- Creating foreign key on [User__OID_] in table 'UserSession_'
ALTER TABLE [dbo].[UserSession_]
ADD CONSTRAINT [FK_UserOID_37C3E18DECA55F5059911C9A2BAE7E88]
    FOREIGN KEY ([User__OID_])
    REFERENCES [dbo].[User_]
        ([OID_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserOID_37C3E18DECA55F5059911C9A2BAE7E88'
CREATE INDEX [IX_FK_UserOID_37C3E18DECA55F5059911C9A2BAE7E88]
ON [dbo].[UserSession_]
    ([User__OID_]);
GO

-- Creating foreign key on [VisitStatusEnum__Code_] in table 'Visit_'
ALTER TABLE [dbo].[Visit_]
ADD CONSTRAINT [FK_Status_EC31B9C320DB0F8E2AAFCE6BE943E79D]
    FOREIGN KEY ([VisitStatusEnum__Code_])
    REFERENCES [dbo].[VisitStatusEnum_]
        ([Code_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Status_EC31B9C320DB0F8E2AAFCE6BE943E79D'
CREATE INDEX [IX_FK_Status_EC31B9C320DB0F8E2AAFCE6BE943E79D]
ON [dbo].[Visit_]
    ([VisitStatusEnum__Code_]);
GO

-- Creating foreign key on [InformationAuthorityEnum_Code_] in table 'PatientProfile_'
ALTER TABLE [dbo].[PatientProfile_]
ADD CONSTRAINT [FK_InformationAuthorityEnum_PatientProfile_]
    FOREIGN KEY ([InformationAuthorityEnum_Code_])
    REFERENCES [dbo].[InformationAuthorityEnum_]
        ([Code_])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_InformationAuthorityEnum_PatientProfile_'
CREATE INDEX [IX_FK_InformationAuthorityEnum_PatientProfile_]
ON [dbo].[PatientProfile_]
    ([InformationAuthorityEnum_Code_]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------